home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ktencode / readthis.txt < prev    next >
Encoding:
Text File  |  1994-06-23  |  8.3 KB  |  208 lines

  1.                        KTEncrypt  Version 1.0
  2.                        ----------------------
  3.  
  4. Thank you for downloading  these files entitled KTEncrypt.
  5. This file was written by Karl D. Albrecht for immediate use with
  6. Visual Basic for Windows.  This code is used for file security.
  7. when you wish to write something to a file and not have it read,
  8. you use this function and the text gets altered to a format that is
  9. unreadable.  All you do is supply it a string you want to encrypt and
  10. a password and the Function will return a uniquely encrypted string
  11. based solely on the password provided.  The benefit of this is you
  12. do not need to keep the password in a file anywhere to compare.  If
  13. you use the wrong password a useless, unreadable string is returned.
  14.  
  15.  
  16.  
  17. DISCLAIMER: Karl Albrecht takes no responsibility for anything caused
  18.             by this function. USE AT YOUR OWN RISK!
  19.  
  20.  
  21. You may use this function as you see fit, and modify it in any way,
  22. but with one request from the author, that if you like it, and/or
  23. you have any suggestions or improvements you drop a note to one of
  24. the following places:
  25.  
  26. BY POSTAGE SEND TO:
  27.                      K & T
  28.                  KARL D ALBRECHT
  29.                   P.O. Box 478
  30.            SAN LORENZO, CA 94580-0478
  31.  
  32. FROM AMERICA ON-LINE:              KARL25
  33. FROM COMPUSERVE:                  >INTERNET KARL25@aol.com
  34. FROM ELSEWHERE ON THE INTERNET:   KARL25@aol.com
  35.  
  36. NOTICE: You may distribute and Upload to BBS as you like, under
  37.         the following terms:
  38.  
  39.        1) You must include ALL the file it came with.
  40.        2) All files must be in original format UNMODIFIED.
  41.        3) You must upload the in zipped fashion.
  42.  
  43. The following is a list and explanation of the included files:
  44.  
  45.     KTENCODE.EXE  - Compiled demo program
  46.     KTENCODE.MAK  - VBWIN  3.0 Sample code project for KTENCODE.EXE
  47.     KTENCODE.FRM  - VBWIN  3.0 Sample code form for KTENCODE.EXE
  48.     
  49.     VBWIN30.BAS   - VBWIN 3.0 Module with Function loaded in
  50.     QUICKBAS.BAS  - QuickBASIC DEMO program with modified function
  51.     QBASIC.BAS    - QBasic DEMO program with modified function
  52.  
  53.     KTENCODE.TXT  - ORIGINAL VBWIN 3.0 Code saved as ASCII
  54.  
  55.     READTHIS.TXT  - This file that you are reading
  56.  
  57.          Thank You Very Much For Your Cooperation!
  58.  
  59.  
  60. FUNCTION EXPLANATION:
  61. ---------------------
  62.     This function is designed in and for use with Visual Basic
  63.     for Windows Version 3.0, but can be ported to other 'basics' with
  64.     little modification.  In short, this Function will allow you to
  65.     encode a string using a supplied password to make it unreadable
  66.     to all that do not posses the password.  It does this by altering
  67.     each individual ASCII code by different amounts.  The amount each
  68.     character is altered is solely dependent on the password supplied.
  69.     That means strings are encoded differently if they have a different
  70.     password!  WARNING!!  If you forget your password, your data is gone.
  71.     
  72. NOTE:    I wrote this password to be completely self contained.  It does
  73.          not make any calls outside of itself and relies on no variables
  74.          outside of it aside from what is passed directly to it.  This may
  75.          cause the code to appear a bit crowded but it will make it easier
  76.          to incorporate it into your code.
  77.  
  78. TO USE:  To use this Function simply copy and paste it into a Module (*.BAS)
  79.          or directly into a form.  Once that done, it is ready for use.
  80.  
  81.  
  82.  
  83.  
  84. SYNTAX:   (STRING VARIABLE FUNCTION)
  85.  
  86. KTEncrypt (password$, string$, flag%, Errors$)
  87.  
  88. where:
  89.  
  90.  
  91. password$ - is the password to use in the encoding.  Must be at
  92.             least 1 character long and can be any characters.  If
  93.             password$="" then the function will abort and
  94.             Errors$ will be set to "NO PASSWORD!"
  95.  
  96. string$   - This is the string to encode.  Must be at least 1
  97.             character long.  If not Errors$ will be set to
  98.             "NO STRING!"
  99.  
  100. Flag%     - This is the Encode or Decode F]ag.  If it is set to
  101.             0 then it will encode.  If set to anything else it
  102.             will decode.
  103.  
  104. Errors$   - This is just a blank string (CAN BE ANY NAME) that
  105.             is used to return errors.  If an error occurs the
  106.             Function will abort and the function will return the
  107.             original unmodified string.  Errors$ will be set
  108.             to one of the following:
  109.  
  110.           1- "NO PASSWORD!"  - means password$ = ""
  111.  
  112.           2- "NO STRING!"    - means string$ = ""
  113.  
  114.           3- "FILE ALREADY ENCODED!" - means that you are attempting
  115.                                        to encoded an already encoded
  116.                                        file!
  117.           4- "FILE NOT ENCODED!" - means that you are attempting to
  118.                                    decode a file that has not been
  119.                                    encoded .
  120.  
  121.           5- "INVALID PASSWORD!" - means an error incurred while
  122.                                    decoding that could only result
  123.                                    from an invalid password.
  124.  
  125.  
  126.  
  127. Errors 1 and 2 are self explanatory.  Errors 3-5 are the result of some
  128. special encoding.  One problem that I was having originally is that
  129. occasionally a password may encode a string and try and change one
  130. of it's characters to a value <0 or >255.  This would cause an error.
  131. In order to not limit the password or the string I designed a feature
  132. to fix this.  This modification needed to know if it was encoding or
  133. decoding the file.  An encoded file has a bunch of CHR$(255)'s tacked
  134. onto the end to identify it as encoded.  So this will prevent from
  135. encoding an encoded file or decoding a not encoded file.  Sometimes
  136. when decoding a file with the wrong password two things may happen.  One
  137. the Function will incur an error because an ASCII value is <O or >255
  138. (this can happen because the checking does not occur on decoding) if this
  139. happens the function will end and Errors$ will be set to "INVALID PASSWORD"
  140. The second thing that can happen is no errors will occur and the
  141. function will return a scrambled file which is useless.  If you don't
  142. want that to happen then encode the password in with the file and
  143. decode it first if they don't match then don't decode the rest.
  144.  
  145. note that these are just errors specific to my function.  Run time errors
  146. can occur and should only happen if you invoke the function with the wrong
  147. parameters.  The function does have an ON LOCAL ERROR routine that is used
  148. to trap the custom errors.  If a run-time error occurs that was not planned
  149. it will abort the function and return the Error Name in the Errors$.
  150.  
  151. NOTE:  Two of the errors can be overrided.  'FILE ALREADY ENCODED' and
  152.        'FILE NOTE ENCODED!' can be forced so that the Function will
  153.        encrypt or de-encrypt anyway.  This is useful if you wish to double
  154.        encrypt a file (or more times!).  Normally you don't want to
  155.        encrypt more than once because if you forget how many times you did
  156.        encrypt it you may have trouble restoring the file!  Also if a file
  157.        was damaged or lost it's trailing CHR$(255)'s it may not see it
  158.        as Encrypted but you can force it so you can recover the data.  To
  159.        ignore these two errors simply set Errors$="FORCE" prior to calling
  160.        the Function (it is not case sensitive).  Try it!!
  161.  
  162.  
  163. EXAMPLES:
  164.  
  165. 'assumes that there is an array called MyText$() loaded with text to save
  166. 'Also assumes a password has been entered by user called password$
  167.  
  168.  
  169. OPEN "SAVETEXT.TXT" FOR OUTPUT AS 1
  170.  
  171. For Looper = 1 to 20
  172.  
  173.   Scramble$ = KTEncrypt (password$, MyText$(Looper), 0, Errors$)
  174.  
  175.   If Errors$<>"" THEN GOSUB ErrorHandler:
  176.  
  177.   PRINT #1, Scramble$
  178.  
  179. NEXT Looper
  180.  
  181. .
  182. .
  183. .
  184.  
  185.  
  186. ErrorHandler:
  187.  
  188.   ..Code to detect and handle the returned error codes
  189.  
  190.  
  191. This example would scramble each string in turn using the password$ and then
  192. save it to the file.  To decode it would be very similar but the syntax would 
  193. be:
  194.  
  195.    UnScramble$ = KTEncrypt (password$, MyText$(Looper), 1, Errors$)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. IF YOU HAVE ANY QUESTIONS OR COMMENTS PLEASE FEEL FREE TO WRITE 
  205. TO ME AT THE ABOVE ADDRESSES. HOPE YOU ENJOY IT. 
  206.                                      
  207.                                 THANKS A LOT FOR YOUR COOPERATION,
  208.                                                     KARL ALBRECHTPK  Ç ╕╘U    &z≡  +&      KTENCODE.EXEφ:mpT